<?php
namespace app\index\controller;

use app\index\model\CompanyModel;
use app\index\model\WarnModel;
use app\index\service\WarnService;
use think\facade\Config;
use think\Request;

class Task extends Access
{

    public function __construct(Request $request)
    {
        parent::__construct();
        $key = $request->param('key');
        $config_key = Config::get('service.task_key');
        if($key != $config_key){
            exit('server error');
        }
    }


    public function warn(){
        $com = CompanyModel::field('id')->where(['deleted_user'=>0])->select();
        if(count($com) < 1){
            return true;
        }
        foreach ($com as $item){
            $this->com_task($item['id']);
        }
        exit('success');
    }


    public function com_task($comid){
        $data = WarnModel::where(['comid'=>$comid,'state'=>1])->select()->toArray();
        $Obj = new WarnService();
        foreach ($data as $item){
            call_user_func(array($Obj, $item['modname']), $item);
        }
        exit('success');
    }




}
